home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15219 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  908 b 

  1. Path: news.magi.com!newsadm
  2. From: mlefebvr@magi.com (Michel L.)
  3. Newsgroups: comp.lang.c
  4. Subject: double-->float... number changes
  5. Date: Wed, 17 Apr 1996 21:43:17 GMT
  6. Organization: Magi Data Consulting
  7. Message-ID: <4l3olr$85o@news.magi.com>
  8. NNTP-Posting-Host: magi04p65.magi.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. I have a number (that I pick up from Sybase), declared as a double,
  12. it's value is 123.4, I then want to store it in a float variable, but
  13. the number changes to 123.399994.
  14.  
  15. float flt_number=0;
  16. double dbl_number=123.4;
  17. flt_number = dbl_number;
  18.  
  19. flt_number is 123.399994.
  20.  
  21. This messes up calculations later on in program.
  22. I tried converting the number to a string and using atof() to get a
  23. float number, but this function returns a double?!, and the subsequent
  24. conversion to a float produces the same error.
  25.  
  26. Is there a way to get 123.4 when converting to a float number?
  27.  
  28. Thanks in advance!
  29.  
  30.